<template>
<h2>添加房号</h2>

<table class="table table-bordered">
    
                <tr>
                    
           <th>房型</th>
           <th>
            <select v-model="AddH.xid">
                <option value="-1">--请选择房型---</option>
                <option v-for="item in Show1" :value="item.fid">{{ item.fname }}</option>
            </select>
           </th>
                </tr>

            <tr>
                <th>房间号码</th>
                <th>
                    <input type="text" v-model="AddH.hname">
                </th>
            </tr>

            <tr>
                <th>房号描述</th>
                <th>
                    <textarea v-model="AddH.hMianShu"></textarea>
                </th>
            </tr>


         <tr>
                <th>状态</th>
                <th>
                   <input type="radio" :value="true" v-model="AddH.isState">上架
                   <input type="radio" :value="false" v-model="AddH.isState">下架

                </th>
            </tr>

            <tr>
                <th></th>
                <th>
                        <button @click="Addh1" class="btn btn-success">添加</button>

                </th>
            </tr>

   








</table>




</template>


<script setup lang="ts">


import{onMounted, ref} from 'vue'
import axios from 'axios';

onMounted(()=>{  //钩子函数

    Show();
})

//定义一个响应式数据接收后台的数据
const Show1=ref([{  
     "fid": -1,
      "fname": "",
      "price": 10,
      "mianJI": 10,
      "num": 1,
      "img": "1",
      "mianShu": "不好用",
      "isWindow": true,
      "isDel": true


}])
//创建响应式数据接收显示查询条件
const FenYe=ref({

s:1,
m:3,
count:0,
Zy:0,
FName:""

})


///显示房型方法

const Show=()=>{

axios.get('https://localhost:7247/api/FangXing/ShowFangXing',{params:{

       s:1,
       m:9999,
       FName:FenYe.value.FName

}}).then(res=>{

   Show1.value=res.data.data,
   FenYe.value.count=res.data.count
   FenYe.value.Zy=res.data.zy

})

}












import { useRouter,createRouter } from 'vue-router';


const router =useRouter();
//添加房号响应式数据
const AddH=ref({

"hid": 0,
  "xid": -1,
  "hname": 0,
  "hMianShu": "",
  "isState": true,
  "isDel": true

})
//添加房号的方法
const Addh1=()=>{

if(AddH.value.xid==-1)
{
    alert('请选择房型')
    return ;
}

if(AddH.value.hname==0)
{
    alert('请添加房号信息')
    return ;
}
if(AddH.value.hMianShu=="")
{
    alert('描述不能为空')
    return ;
}


axios.post('https://localhost:7247/api/FangHao/AddFh',AddH.value).then(res=>{

    if(res.data>0)
{
    alert('添加成功')
    router.push('/ShowFangHao')
}
else
{
    alert('添加失败')
}
})


}










</script>